1. Field of the Invention
The present invention generally relates to computer processing techniques and, in particular, to a system and method for enabling selective execution of certain sets of code within a computer program without significantly affecting the execution performance of the program.
2. Related Art
In some computer applications, it is desirable to perform certain functionality only in a limited number of circumstances. For example, a computer program may include testing code (e.g., assertions) that test for certain conditions to ensure that the program is running correctly. While it may be desirable to run this testing code during the debugging and/or testing phases, it may be less desirable to run this testing code in normal operation, since the testing code utilizes processor time. In this regard, execution of the testing code is not required for the computer program to operate correctly and is only useful if there is an error that can be detected by the testing code. Thus, executing the testing code when the computer program runs free of errors needlessly utilizes processor time.
As a result, most computer programs that include testing code are usually recompiled once the testing and debugging phases are complete. During recompilation, insertion of testing code into the recompiled programs is prevented such that the recompiled programs do not include any testing code. The recompiled programs run more efficiently since there is no testing code to execute, and it is these recompiled programs that are usually sold to and used by consumers.
However, even after the testing and debugging phases have been completed, there may still be some bugs in the computer program that could be detected by the removed testing code, and once the testing code has been removed, the computer program lacks the capability of detecting these bugs. Therefore, a tradeoff exists between leaving testing code in a computer program and removing the testing code from the computer program. In this regard, the testing code may be removed from the computer program to improve the performance of the program, or the testing code may be left in the program to test for certain errors, thereby adversely affecting the program""s performance.
When the testing code is included in the program, there are steps that can be taken to mitigate the adverse effect of the code en the program""s performance. For example, conditional branches (e.g., xe2x80x9cIFxe2x80x9d instructions) based on user inputs, or other types of inputs, can be inserted into the program to branch around portions of the testing code when execution of the testing code is not desired. However, the number of these conditional branches can be relatively large when the testing code is spread throughout the program. Therefore, although the adverse impact of testing code in a computer program can be mitigated, there still exists at least some impact to the program""s performance, whether or not the testing code is executed, and this impact can be significant.
Thus, a heretofore unaddressed need exists in the industry for providing a system and method of enabling selective execution of certain code (e.g., testing code) within a computer program based on inputs at run time with minimal or no affect to the program""s performance when execution of the foregoing code is not desired.
The present invention overcomes the inadequacies and deficiencies of the prior art as discussed hereinbefore. Generally, the present invention provides a system and method for selectively executing sets of code in computer programs.
In architecture, the system of the present invention utilizes memory for storing a computer program and processing circuitry for processing and executing instructions of the computer program. In particular, the computer program includes a set of code and an unconditional branch instruction. The processing circuitry, in executing the computer program, receives run time data indicative of whether the set of code is enabled or disabled, and based on the run time data, the processing circuitry sets a value of a mode indicator. While the program is running, the processing circuitry receives and processes the unconditional branch instruction. When the set of code is disabled, the processing circuitry executes the unconditional branch instruction based on the mode indicator, thereby preventing execution of the set of code. However, when the set of code is enabled, the processing circuitry refrains from executing the unconditional branch instruction based on the mode indicator and executes the set of code. Thus, execution of the set of code is selectively enabled based on the status of the mode indicator.
The present invention can also be viewed as providing a method for selectively executing sets of code in computer programs. The method can be broadly conceptualized by the following steps: storing a computer program, the computer program having a set of code and an unconditional branch instruction; receiving run time data, during a run of the program, indicating whether the set of code is enabled; setting a value of a mode indicator based on the run time data; determining whether to execute the unconditional branch instruction based on the value of the mode indicator; processing the unconditional branch instruction based on the determining step; and executing the set of code if a determination is made in the determining step to refrain from executing the first unconditional branch instruction.
Other features and advantages of the present invention will become apparent to one skilled in the art upon examination of the following detailed description, when read in conjunction with the accompanying drawings. It is intended that all such features and advantages be included herein within the scope of the present invention and protected by the claims.